home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / djgpp / src / gdb-4.12 / gdb / stack.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-03  |  37.6 KB  |  1,404 lines

  1. /* Print and select stack frames for GDB, the GNU debugger.
  2.    Copyright 1986, 1987, 1989, 1991, 1992, 1993 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "defs.h"
  21. #include "value.h"
  22. #include "symtab.h"
  23. #include "gdbtypes.h"
  24. #include "expression.h"
  25. #include "language.h"
  26. #include "frame.h"
  27. #include "gdbcmd.h"
  28. #include "gdbcore.h"
  29. #include "target.h"
  30. #include "breakpoint.h"
  31. #include "demangle.h"
  32. #include "inferior.h"
  33.  
  34. static void
  35. return_command PARAMS ((char *, int));
  36.  
  37. static void
  38. down_command PARAMS ((char *, int));
  39.  
  40. static void
  41. down_silently_command PARAMS ((char *, int));
  42.  
  43. static void
  44. up_command PARAMS ((char *, int));
  45.  
  46. static void
  47. up_silently_command PARAMS ((char *, int));
  48.  
  49. static void
  50. frame_command PARAMS ((char *, int));
  51.  
  52. static void
  53. select_frame_command PARAMS ((char *, int));
  54.  
  55. static void
  56. args_info PARAMS ((char *, int));
  57.  
  58. static void
  59. print_frame_arg_vars PARAMS ((FRAME, GDB_FILE *));
  60.  
  61. static void
  62. catch_info PARAMS ((char *, int));
  63.  
  64. static void
  65. locals_info PARAMS ((char *, int));
  66.  
  67. static void
  68. print_frame_label_vars PARAMS ((FRAME, int, GDB_FILE *));
  69.  
  70. static void
  71. print_frame_local_vars PARAMS ((FRAME, GDB_FILE *));
  72.  
  73. static int
  74. print_block_frame_labels PARAMS ((struct block *, int *, GDB_FILE *));
  75.  
  76. static int
  77. print_block_frame_locals PARAMS ((struct block *, FRAME, GDB_FILE *));
  78.  
  79. static void
  80. backtrace_command PARAMS ((char *, int));
  81.  
  82. static FRAME
  83. parse_frame_specification PARAMS ((char *));
  84.  
  85. static void
  86. frame_info PARAMS ((char *, int));
  87.  
  88.  
  89. extern int addressprint;    /* Print addresses, or stay symbolic only? */
  90. extern int info_verbose;    /* Verbosity of symbol reading msgs */
  91. extern int lines_to_list;    /* # of lines "list" command shows by default */
  92.  
  93. /* The "selected" stack frame is used by default for local and arg access.
  94.    May be zero, for no selected frame.  */
  95.  
  96. FRAME selected_frame;
  97.  
  98. /* Level of the selected frame:
  99.    0 for innermost, 1 for its caller, ...
  100.    or -1 for frame specified by address with no defined level.  */
  101.  
  102. int selected_frame_level;
  103.  
  104. /* Nonzero means print the full filename and linenumber
  105.    when a frame is printed, and do so in a format programs can parse.  */
  106.  
  107. int frame_file_full_name = 0;
  108.  
  109.  
  110. struct print_stack_frame_args {
  111.   struct frame_info *fi;
  112.   int level;
  113.   int source;
  114.   int args;
  115. };
  116.  
  117. static int print_stack_frame_stub PARAMS ((char *));
  118.  
  119. /* Pass the args the way catch_errors wants them.  */
  120. static int
  121. print_stack_frame_stub (args)
  122.      char *args;
  123. {
  124.   struct print_stack_frame_args *p = (struct print_stack_frame_args *)args;
  125.   print_frame_info (p->fi, p->level, p->source, p->args);
  126.   return 0;
  127. }
  128.  
  129. /* Print a stack frame briefly.  FRAME should be the frame id
  130.    and LEVEL should be its level in the stack (or -1 for level not defined).
  131.    This prints the level, the function executing, the arguments,
  132.    and the file name and line number.
  133.    If the pc is not at the beginning of the source line,
  134.    the actual pc is printed at the beginning.
  135.  
  136.    If SOURCE is 1, print the source line as well.
  137.    If SOURCE is -1, print ONLY the source line.  */
  138.  
  139. void
  140. print_stack_frame (frame, level, source)
  141.      FRAME frame;
  142.      int level;
  143.      int source;
  144. {
  145.   struct print_stack_frame_args args;
  146.  
  147.   args.fi = get_frame_info (frame);
  148.   args.level = level;
  149.   args.source = source;
  150.   args.args = 1;
  151.  
  152.   catch_errors (print_stack_frame_stub, (char *)&args, "", RETURN_MASK_ERROR);
  153. }
  154.  
  155. struct print_args_args {
  156.   struct symbol *func;
  157.   struct frame_info *fi;
  158. };
  159.  
  160. static int print_args_stub PARAMS ((char *));
  161.  
  162. /* Pass the args the way catch_errors wants them.  */
  163. static int
  164. print_args_stub (args)
  165.      char *args;
  166. {
  167.   int numargs;
  168.   struct print_args_args *p = (struct print_args_args *)args;
  169.   FRAME_NUM_ARGS (numargs, (p->fi));
  170.   print_frame_args (p->func, p->fi, numargs, gdb_stdout);
  171.   return 0;
  172. }
  173.  
  174. void
  175. print_frame_info (fi, level, source, args)
  176.      struct frame_info *fi;
  177.      register int level;
  178.      int source;
  179.      int args;
  180. {
  181.   struct symtab_and_line sal;
  182.   struct symbol *func;
  183.   register char *funname = 0;
  184.   enum language funlang = language_unknown;
  185.   char buf[MAX_REGISTER_RAW_SIZE];
  186.   CORE_ADDR sp;
  187.  
  188. #if 0
  189.   /* On the 68k, this spends too much time in m68k_find_saved_regs.  */
  190.  
  191.   /* Get the value of SP_REGNUM relative to the frame.  */
  192.   get_saved_register (buf, (int *)NULL, (CORE_ADDR *)NULL,
  193.               FRAME_INFO_ID (fi), SP_REGNUM, (enum lval_type *)NULL);
  194.   sp = extract_address (buf, REGISTER_RAW_SIZE (SP_REGNUM));
  195.  
  196.   /* This is not a perfect test, because if a function alloca's some
  197.      memory, puts some code there, and then jumps into it, then the test
  198.      will succeed even though there is no call dummy.  Probably best is
  199.      to check for a bp_call_dummy breakpoint.  */
  200.   if (PC_IN_CALL_DUMMY (fi->pc, sp, fi->frame))
  201. #else
  202.   if (frame_in_dummy (fi))
  203. #endif
  204.     {
  205.       /* Do this regardless of SOURCE because we don't have any source
  206.      to list for this frame.  */
  207.       if (level >= 0)
  208.     printf_filtered ("#%-2d ", level);
  209.       printf_filtered ("<function called from gdb>\n");
  210.       return;
  211.     }
  212.   if (fi->signal_handler_caller)
  213.     {
  214.       /* Do this regardless of SOURCE because we don't have any source
  215.      to list for this frame.  */
  216.       if (level >= 0)
  217.     printf_filtered ("#%-2d ", level);
  218.       printf_filtered ("<signal handler called>\n");
  219.       return;
  220.     }
  221.  
  222.   /* If fi is not the innermost frame, that normally means that fi->pc
  223.      points to *after* the call instruction, and we want to get the line
  224.      containing the call, never the next line.  But if the next frame is
  225.      a signal_handler_caller frame, then the next frame was not entered
  226.      as the result of a call, and we want to get the line containing
  227.      fi->pc.  */
  228.   sal =
  229.     find_pc_line (fi->pc,
  230.           fi->next != NULL && fi->next->signal_handler_caller == 0);
  231.  
  232.   func = find_pc_function (fi->pc);
  233.   if (func)
  234.     {
  235.       /* In certain pathological cases, the symtabs give the wrong
  236.      function (when we are in the first function in a file which
  237.      is compiled without debugging symbols, the previous function
  238.      is compiled with debugging symbols, and the "foo.o" symbol
  239.      that is supposed to tell us where the file with debugging symbols
  240.      ends has been truncated by ar because it is longer than 15
  241.      characters).  This also occurs if the user uses asm() to create
  242.      a function but not stabs for it (in a file compiled -g).
  243.  
  244.      So look in the minimal symbol tables as well, and if it comes
  245.      up with a larger address for the function use that instead.
  246.      I don't think this can ever cause any problems; there shouldn't
  247.      be any minimal symbols in the middle of a function; if this is
  248.      ever changed many parts of GDB will need to be changed (and we'll
  249.      create a find_pc_minimal_function or some such).  */
  250.  
  251.       struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
  252.       if (msymbol != NULL
  253.       && (SYMBOL_VALUE_ADDRESS (msymbol) 
  254.           > BLOCK_START (SYMBOL_BLOCK_VALUE (func))))
  255.     {
  256.       /* In this case we have no way of knowing the source file
  257.          and line number, so don't print them.  */
  258.       sal.symtab = 0;
  259.       /* We also don't know anything about the function besides
  260.          its address and name.  */
  261.       func = 0;
  262.       funname = SYMBOL_NAME (msymbol);
  263.       funlang = SYMBOL_LANGUAGE (msymbol);
  264.     }
  265.       else
  266.     {
  267.       funname = SYMBOL_NAME (func);
  268.       funlang = SYMBOL_LANGUAGE (func);
  269.     }
  270.     }
  271.   else
  272.     {
  273.       register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
  274.       if (msymbol != NULL)
  275.     {
  276.       funname = SYMBOL_NAME (msymbol);
  277.       funlang = SYMBOL_LANGUAGE (msymbol);
  278.     }
  279.     }
  280.  
  281.   if (source >= 0 || !sal.symtab)
  282.     {
  283.       if (level >= 0)
  284.     printf_filtered ("#%-2d ", level);
  285.       if (addressprint)
  286.     if (fi->pc != sal.pc || !sal.symtab)
  287.       printf_filtered ("%s in ", local_hex_string((unsigned long) fi->pc));
  288.       fprintf_symbol_filtered (gdb_stdout, funname ? funname : "??", funlang,
  289.                    DMGL_ANSI);
  290.       wrap_here ("   ");
  291.       fputs_filtered (" (", gdb_stdout);
  292.       if (args)
  293.     {
  294.       struct print_args_args args;
  295.       args.fi = fi;
  296.       args.func = func;
  297.       catch_errors (print_args_stub, (char *)&args, "", RETURN_MASK_ERROR);
  298.     }
  299.       printf_filtered (")");
  300.       if (sal.symtab && sal.symtab->filename)
  301.     {
  302.           wrap_here ("   ");
  303.       printf_filtered (" at %s:%d", sal.symtab->filename, sal.line);
  304.     }
  305.  
  306. #ifdef PC_LOAD_SEGMENT
  307.      /* If we couldn't print out function name but if can figure out what
  308.         load segment this pc value is from, at least print out some info
  309.     about its load segment. */
  310.       if (!funname) {
  311.     wrap_here ("  ");
  312.     printf_filtered (" from %s", PC_LOAD_SEGMENT (fi->pc));
  313.       }
  314. #endif
  315.       printf_filtered ("\n");
  316.     }
  317.  
  318.   if ((source != 0) && sal.symtab)
  319.     {
  320.       int done = 0;
  321.       int mid_statement = source < 0 && fi->pc != sal.pc;
  322.       if (frame_file_full_name)
  323.     done = identify_source_line (sal.symtab, sal.line, mid_statement,
  324.                      fi->pc);
  325.       if (!done)
  326.     {
  327.       if (addressprint && mid_statement)
  328.         printf_filtered ("%s\t", local_hex_string((unsigned long) fi->pc));
  329.       print_source_lines (sal.symtab, sal.line, sal.line + 1, 0);
  330.     }
  331.       current_source_line = max (sal.line - lines_to_list/2, 1);
  332.     }
  333.   if (source != 0)
  334.     set_default_breakpoint (1, fi->pc, sal.symtab, sal.line);
  335.  
  336.   gdb_flush (gdb_stdout);
  337. }
  338.  
  339. /*
  340.  * Read a frame specification in whatever the appropriate format is.
  341.  * Call error() if the specification is in any way invalid (i.e.
  342.  * this function never returns NULL).
  343.  */
  344. static FRAME
  345. parse_frame_specification (frame_exp)
  346.      char *frame_exp;
  347. {
  348.   int numargs = 0;
  349. #define    MAXARGS    4
  350.   CORE_ADDR args[MAXARGS];
  351.   
  352.   if (frame_exp)
  353.     {
  354.       char *addr_string, *p;
  355.       struct cleanup *tmp_cleanup;
  356.  
  357.       while (*frame_exp == ' ') frame_exp++;
  358.  
  359.       while (*frame_exp)
  360.     {
  361.       if (numargs > MAXARGS)
  362.         error ("Too many args in frame specification");
  363.       /* Parse an argument.  */
  364.           for (p = frame_exp; *p && *p != ' '; p++)
  365.         ;
  366.       addr_string = savestring(frame_exp, p - frame_exp);
  367.  
  368.       {
  369.         tmp_cleanup = make_cleanup (free, addr_string);
  370.         args[numargs++] = parse_and_eval_address (addr_string);
  371.         do_cleanups (tmp_cleanup);
  372.       }
  373.  
  374.       /* Skip spaces, move to possible next arg.  */
  375.       while (*p == ' ') p++;
  376.       frame_exp = p;
  377.     }
  378.     }
  379.  
  380.   switch (numargs)
  381.     {
  382.     case 0:
  383.       if (selected_frame == NULL)
  384.     error ("No selected frame.");
  385.       return selected_frame;
  386.       /* NOTREACHED */
  387.     case 1:
  388.       {
  389.     int level = args[0];
  390.     FRAME fid = find_relative_frame (get_current_frame (), &level);
  391.     FRAME tfid;
  392.  
  393.     if (level == 0)
  394.       /* find_relative_frame was successful */
  395.       return fid;
  396.  
  397.     /* If (s)he specifies the frame with an address, he deserves what
  398.        (s)he gets.  Still, give the highest one that matches.  */
  399.  
  400.     for (fid = get_current_frame ();
  401.          fid && FRAME_FP (fid) != args[0];
  402.          fid = get_prev_frame (fid))
  403.       ;
  404.  
  405.     if (fid)
  406.       while ((tfid = get_prev_frame (fid)) &&
  407.          (FRAME_FP (tfid) == args[0]))
  408.         fid = tfid;
  409.       
  410.     /* We couldn't identify the frame as an existing frame, but
  411.        perhaps we can create one with a single argument.
  412.        Fall through to default case; it's up to SETUP_ARBITRARY_FRAME
  413.        to complain if it doesn't like a single arg.  */
  414.       }
  415.  
  416.      default:
  417. #ifdef SETUP_ARBITRARY_FRAME
  418.       return SETUP_ARBITRARY_FRAME (numargs, args);
  419. #else
  420.       /* Usual case.  Do it here rather than have everyone supply
  421.      a SETUP_ARBITRARY_FRAME that does this.  */
  422.       if (numargs == 1)
  423.     return create_new_frame (args[0], 0);
  424.       error ("Too many args in frame specification");
  425. #endif
  426.       /* NOTREACHED */
  427.     }
  428.   /* NOTREACHED */
  429. }
  430.  
  431. /* FRAME_ARGS_ADDRESS_CORRECT is just like FRAME_ARGS_ADDRESS except
  432.    that if it is unsure about the answer, it returns 0
  433.    instead of guessing (this happens on the VAX and i960, for example).
  434.  
  435.    On most machines, we never have to guess about the args address,
  436.    so FRAME_ARGS_ADDRESS{,_CORRECT} are the same.  */
  437. #if !defined (FRAME_ARGS_ADDRESS_CORRECT)
  438. #define FRAME_ARGS_ADDRESS_CORRECT FRAME_ARGS_ADDRESS
  439. #endif
  440.  
  441. /* Print verbosely the selected frame or the frame at address ADDR.
  442.    This means absolutely all information in the frame is printed.  */
  443.  
  444. static void
  445. frame_info (addr_exp, from_tty)
  446.      char *addr_exp;
  447.      int from_tty;
  448. {
  449.   FRAME frame;
  450.   struct frame_info *fi;
  451.   struct frame_saved_regs fsr;
  452.   struct symtab_and_line sal;
  453.   struct symbol *func;
  454.   struct symtab *s;
  455.   FRAME calling_frame;
  456.   int i, count;
  457.   char *funname = 0;
  458.   enum language funlang = language_unknown;
  459.  
  460.   if (!target_has_stack)
  461.     error ("No stack.");
  462.  
  463.   frame = parse_frame_specification (addr_exp);
  464.   if (!frame)
  465.     error ("Invalid frame specified.");
  466.  
  467.   fi = get_frame_info (frame);
  468.   sal = find_pc_line (fi->pc,
  469.               fi->next != NULL && fi->next->signal_handler_caller == 0);
  470.   func = get_frame_function (frame);
  471.   s = find_pc_symtab(fi->pc);
  472.   if (func)
  473.     {
  474.       funname = SYMBOL_NAME (func);
  475.       funlang = SYMBOL_LANGUAGE (func);
  476.     }
  477.   else
  478.     {
  479.       register struct minimal_symbol *msymbol = lookup_minimal_symbol_by_pc (fi->pc);
  480.       if (msymbol != NULL)
  481.     {
  482.       funname = SYMBOL_NAME (msymbol);
  483.       funlang = SYMBOL_LANGUAGE (msymbol);
  484.     }
  485.     }
  486.   calling_frame = get_prev_frame (frame);
  487.  
  488.   if (!addr_exp && selected_frame_level >= 0) {
  489.     printf_filtered ("Stack level %d, frame at %s:\n",
  490.              selected_frame_level, 
  491.              local_hex_string((unsigned long) FRAME_FP(frame)));
  492.   } else {
  493.     printf_filtered ("Stack frame at %s:\n",
  494.              local_hex_string((unsigned long) FRAME_FP(frame)));
  495.   }
  496.   printf_filtered (" %s = %s",
  497.            reg_names[PC_REGNUM], 
  498.            local_hex_string((unsigned long) fi->pc));
  499.  
  500.   wrap_here ("   ");
  501.   if (funname)
  502.     {
  503.       printf_filtered (" in ");
  504.       fprintf_symbol_filtered (gdb_stdout, funname, funlang,
  505.                    DMGL_ANSI | DMGL_PARAMS);
  506.     }
  507.   wrap_here ("   ");
  508.   if (sal.symtab)
  509.     printf_filtered (" (%s:%d)", sal.symtab->filename, sal.line);
  510.   puts_filtered ("; ");
  511.   wrap_here ("    ");
  512.   printf_filtered ("saved %s %s\n", reg_names[PC_REGNUM],
  513.            local_hex_string((unsigned long) FRAME_SAVED_PC (frame)));
  514.  
  515.   {
  516.     int frameless = 0;
  517. #ifdef FRAMELESS_FUNCTION_INVOCATION
  518.     FRAMELESS_FUNCTION_INVOCATION (fi, frameless);
  519. #endif
  520.     if (frameless)
  521.       printf_filtered (" (FRAMELESS),");
  522.   }
  523.  
  524.   if (calling_frame)
  525.     printf_filtered (" called by frame at %s", 
  526.              local_hex_string((unsigned long) FRAME_FP (calling_frame)));
  527.   if (fi->next && calling_frame)
  528.     puts_filtered (",");
  529.   wrap_here ("   ");
  530.   if (fi->next)
  531.     printf_filtered (" caller of frame at %s",
  532.              local_hex_string ((unsigned long) fi->next->frame));
  533.   if (fi->next || calling_frame)
  534.     puts_filtered ("\n");
  535.   if (s)
  536.      printf_filtered(" source language %s.\n", language_str(s->language));
  537.  
  538. #ifdef PRINT_EXTRA_FRAME_INFO
  539.   PRINT_EXTRA_FRAME_INFO (fi);
  540. #endif
  541.  
  542.   {
  543.     /* Address of the argument list for this frame, or 0.  */
  544.     CORE_ADDR arg_list = FRAME_ARGS_ADDRESS_CORRECT (fi);
  545.     /* Number of args for this frame, or -1 if unknown.  */
  546.     int numargs;
  547.  
  548.     if (arg_list == 0)
  549.     printf_filtered (" Arglist at unknown address.\n");
  550.     else
  551.       {
  552.     printf_filtered (" Arglist at %s,",
  553.              local_hex_string((unsigned long) arg_list));
  554.  
  555.     FRAME_NUM_ARGS (numargs, fi);
  556.     if (numargs < 0)
  557.       puts_filtered (" args: ");
  558.     else if (numargs == 0)
  559.       puts_filtered (" no args.");
  560.     else if (numargs == 1)
  561.       puts_filtered (" 1 arg: ");
  562.     else
  563.       printf_filtered (" %d args: ", numargs);
  564.     print_frame_args (func, fi, numargs, gdb_stdout);
  565.     puts_filtered ("\n");
  566.       }
  567.   }
  568.   {
  569.     /* Address of the local variables for this frame, or 0.  */
  570.     CORE_ADDR arg_list = FRAME_LOCALS_ADDRESS (fi);
  571.  
  572.     if (arg_list == 0)
  573.     printf_filtered (" Locals at unknown address,");
  574.     else
  575.     printf_filtered (" Locals at %s,",
  576.              local_hex_string((unsigned long) arg_list));
  577.   }
  578.  
  579. #if defined (FRAME_FIND_SAVED_REGS)  
  580.   get_frame_saved_regs (fi, &fsr);
  581.   /* The sp is special; what's returned isn't the save address, but
  582.      actually the value of the previous frame's sp.  */
  583.   printf_filtered (" Previous frame's sp is %s\n", 
  584.            local_hex_string((unsigned long) fsr.regs[SP_REGNUM]));
  585.   count = 0;
  586.   for (i = 0; i < NUM_REGS; i++)
  587.     if (fsr.regs[i] && i != SP_REGNUM)
  588.       {
  589.     if (count == 0)
  590.       puts_filtered (" Saved registers:\n ");
  591.     else
  592.       puts_filtered (",");
  593.     wrap_here (" ");
  594.     printf_filtered (" %s at %s", reg_names[i], 
  595.              local_hex_string((unsigned long) fsr.regs[i]));
  596.     count++;
  597.       }
  598.   if (count)
  599.     puts_filtered ("\n");
  600. #else  /* Have FRAME_FIND_SAVED_REGS.  */
  601.   puts_filtered ("\n");
  602. #endif /* Have FRAME_FIND_SAVED_REGS.  */
  603. }
  604.  
  605. #if 0
  606. /* Set a limit on the number of frames printed by default in a
  607.    backtrace.  */
  608.  
  609. static int backtrace_limit;
  610.  
  611. static void
  612. set_backtrace_limit_command (count_exp, from_tty)
  613.      char *count_exp;
  614.      int from_tty;
  615. {
  616.   int count = parse_and_eval_address (count_exp);
  617.  
  618.   if (count < 0)
  619.     error ("Negative argument not meaningful as backtrace limit.");
  620.  
  621.   backtrace_limit = count;
  622. }
  623.  
  624. static void
  625. backtrace_limit_info (arg, from_tty)
  626.      char *arg;
  627.      int from_tty;
  628. {
  629.   if (arg)
  630.     error ("\"Info backtrace-limit\" takes no arguments.");
  631.  
  632.   printf_unfiltered ("Backtrace limit: %d.\n", backtrace_limit);
  633. }
  634. #endif
  635.  
  636. /* Print briefly all stack frames or just the innermost COUNT frames.  */
  637.  
  638. static void
  639. backtrace_command (count_exp, from_tty)
  640.      char *count_exp;
  641.      int from_tty;
  642. {
  643.   struct frame_info *fi;
  644.   register int count;
  645.   register FRAME frame;
  646.   register int i;
  647.   register FRAME trailing;
  648.   register int trailing_level;
  649.  
  650.   if (!target_has_stack)
  651.     error ("No stack.");
  652.  
  653.   /* The following code must do two things.  First, it must
  654.      set the variable TRAILING to the frame from which we should start
  655.      printing.  Second, it must set the variable count to the number
  656.      of frames which we should print, or -1 if all of them.  */
  657.   trailing = get_current_frame ();
  658.   trailing_level = 0;
  659.   if (count_exp)
  660.     {
  661.       count = parse_and_eval_address (count_exp);
  662.       if (count < 0)
  663.     {
  664.       FRAME current;
  665.  
  666.       count = -count;
  667.  
  668.       current = trailing;
  669.       while (current && count--)
  670.         {
  671.           QUIT;
  672.           current = get_prev_frame (current);
  673.         }
  674.       
  675.       /* Will stop when CURRENT reaches the top of the stack.  TRAILING
  676.          will be COUNT below it.  */
  677.       while (current)
  678.         {
  679.           QUIT;
  680.           trailing = get_prev_frame (trailing);
  681.           current = get_prev_frame (current);
  682.           trailing_level++;
  683.         }
  684.       
  685.       count = -1;
  686.     }
  687.     }
  688.   else
  689.     count = -1;
  690.  
  691.   if (info_verbose)
  692.     {
  693.       struct partial_symtab *ps;
  694.       
  695.       /* Read in symbols for all of the frames.  Need to do this in
  696.      a separate pass so that "Reading in symbols for xxx" messages
  697.      don't screw up the appearance of the backtrace.  Also
  698.      if people have strong opinions against reading symbols for
  699.      backtrace this may have to be an option.  */
  700.       i = count;
  701.       for (frame = trailing;
  702.        frame != NULL && i--;
  703.        frame = get_prev_frame (frame))
  704.     {
  705.       QUIT;
  706.       fi = get_frame_info (frame);
  707.       ps = find_pc_psymtab (fi->pc);
  708.       if (ps)
  709.         PSYMTAB_TO_SYMTAB (ps);    /* Force syms to come in */
  710.     }
  711.     }
  712.  
  713.   for (i = 0, frame = trailing;
  714.        frame && count--;
  715.        i++, frame = get_prev_frame (frame))
  716.     {
  717.       QUIT;
  718.       fi = get_frame_info (frame);
  719.  
  720.       /* Don't use print_stack_frame; if an error() occurs it probably
  721.      means further attempts to backtrace would fail (on the other
  722.      hand, perhaps the code does or could be fixed to make sure
  723.      the frame->prev field gets set to NULL in that case).  */
  724.       print_frame_info (fi, trailing_level + i, 0, 1);
  725.     }
  726.  
  727.   /* If we've stopped before the end, mention that.  */
  728.   if (frame && from_tty)
  729.     printf_filtered ("(More stack frames follow...)\n");
  730. }
  731.  
  732. /* Print the local variables of a block B active in FRAME.
  733.    Return 1 if any variables were printed; 0 otherwise.  */
  734.  
  735. static int
  736. print_block_frame_locals (b, frame, stream)
  737.      struct block *b;
  738.      register FRAME frame;
  739.      register GDB_FILE *stream;
  740. {
  741.   int nsyms;
  742.   register int i;
  743.   register struct symbol *sym;
  744.   register int values_printed = 0;
  745.  
  746.   nsyms = BLOCK_NSYMS (b);
  747.  
  748.   for (i = 0; i < nsyms; i++)
  749.     {
  750.       sym = BLOCK_SYM (b, i);
  751.       switch (SYMBOL_CLASS (sym))
  752.     {
  753.     case LOC_LOCAL:
  754.     case LOC_REGISTER:
  755.     case LOC_STATIC:
  756.     case LOC_BASEREG:
  757.       values_printed = 1;
  758.       fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
  759.       fputs_filtered (" = ", stream);
  760.       print_variable_value (sym, frame, stream);
  761.       fprintf_filtered (stream, "\n");
  762.       break;
  763.  
  764.     default:
  765.       /* Ignore symbols which are not locals.  */
  766.       break;
  767.     }
  768.     }
  769.   return values_printed;
  770. }
  771.  
  772. /* Same, but print labels.  */
  773.  
  774. static int
  775. print_block_frame_labels (b, have_default, stream)
  776.      struct block *b;
  777.      int *have_default;
  778.      register GDB_FILE *stream;
  779. {
  780.   int nsyms;
  781.   register int i;
  782.   register struct symbol *sym;
  783.   register int values_printed = 0;
  784.  
  785.   nsyms = BLOCK_NSYMS (b);
  786.  
  787.   for (i = 0; i < nsyms; i++)
  788.     {
  789.       sym = BLOCK_SYM (b, i);
  790.       if (STREQ (SYMBOL_NAME (sym), "default"))
  791.     {
  792.       if (*have_default)
  793.         continue;
  794.       *have_default = 1;
  795.     }
  796.       if (SYMBOL_CLASS (sym) == LOC_LABEL)
  797.     {
  798.       struct symtab_and_line sal;
  799.       sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
  800.       values_printed = 1;
  801.       fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
  802.       if (addressprint)
  803.         fprintf_filtered (stream, " %s", 
  804.                   local_hex_string((unsigned long) SYMBOL_VALUE_ADDRESS (sym)));
  805.       fprintf_filtered (stream, " in file %s, line %d\n",
  806.                 sal.symtab->filename, sal.line);
  807.     }
  808.     }
  809.   return values_printed;
  810. }
  811.  
  812. /* Print on STREAM all the local variables in frame FRAME,
  813.    including all the blocks active in that frame
  814.    at its current pc.
  815.  
  816.    Returns 1 if the job was done,
  817.    or 0 if nothing was printed because we have no info
  818.    on the function running in FRAME.  */
  819.  
  820. static void
  821. print_frame_local_vars (frame, stream)
  822.      register FRAME frame;
  823.      register GDB_FILE *stream;
  824. {
  825.   register struct block *block = get_frame_block (frame);
  826.   register int values_printed = 0;
  827.  
  828.   if (block == 0)
  829.     {
  830.       fprintf_filtered (stream, "No symbol table info available.\n");
  831.       return;
  832.     }
  833.   
  834.   while (block != 0)
  835.     {
  836.       if (print_block_frame_locals (block, frame, stream))
  837.     values_printed = 1;
  838.       /* After handling the function's top-level block, stop.
  839.      Don't continue to its superblock, the block of
  840.      per-file symbols.  */
  841.       if (BLOCK_FUNCTION (block))
  842.     break;
  843.       block = BLOCK_SUPERBLOCK (block);
  844.     }
  845.  
  846.   if (!values_printed)
  847.     {
  848.       fprintf_filtered (stream, "No locals.\n");
  849.     }
  850. }
  851.  
  852. /* Same, but print labels.  */
  853.  
  854. static void
  855. print_frame_label_vars (frame, this_level_only, stream)
  856.      register FRAME frame;
  857.      int this_level_only;
  858.      register GDB_FILE *stream;
  859. {
  860.   register struct blockvector *bl;
  861.   register struct block *block = get_frame_block (frame);
  862.   register int values_printed = 0;
  863.   int index, have_default = 0;
  864.   char *blocks_printed;
  865.   struct frame_info *fi = get_frame_info (frame);
  866.   CORE_ADDR pc = fi->pc;
  867.  
  868.   if (block == 0)
  869.     {
  870.       fprintf_filtered (stream, "No symbol table info available.\n");
  871.       return;
  872.     }
  873.  
  874.   bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
  875.   blocks_printed = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
  876.   memset (blocks_printed, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
  877.  
  878.   while (block != 0)
  879.     {
  880.       CORE_ADDR end = BLOCK_END (block) - 4;
  881.       int last_index;
  882.  
  883.       if (bl != blockvector_for_pc (end, &index))
  884.     error ("blockvector blotch");
  885.       if (BLOCKVECTOR_BLOCK (bl, index) != block)
  886.     error ("blockvector botch");
  887.       last_index = BLOCKVECTOR_NBLOCKS (bl);
  888.       index += 1;
  889.  
  890.       /* Don't print out blocks that have gone by.  */
  891.       while (index < last_index
  892.          && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
  893.     index++;
  894.  
  895.       while (index < last_index
  896.          && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
  897.     {
  898.       if (blocks_printed[index] == 0)
  899.         {
  900.           if (print_block_frame_labels (BLOCKVECTOR_BLOCK (bl, index), &have_default, stream))
  901.         values_printed = 1;
  902.           blocks_printed[index] = 1;
  903.         }
  904.       index++;
  905.     }
  906.       if (have_default)
  907.     return;
  908.       if (values_printed && this_level_only)
  909.     return;
  910.  
  911.       /* After handling the function's top-level block, stop.
  912.      Don't continue to its superblock, the block of
  913.      per-file symbols.  */
  914.       if (BLOCK_FUNCTION (block))
  915.     break;
  916.       block = BLOCK_SUPERBLOCK (block);
  917.     }
  918.  
  919.   if (!values_printed && !this_level_only)
  920.     {
  921.       fprintf_filtered (stream, "No catches.\n");
  922.     }
  923. }
  924.  
  925. /* ARGSUSED */
  926. static void
  927. locals_info (args, from_tty)
  928.      char *args;
  929.      int from_tty;
  930. {
  931.   if (!selected_frame)
  932.     error ("No frame selected.");
  933.   print_frame_local_vars (selected_frame, gdb_stdout);
  934. }
  935.  
  936. static void
  937. catch_info (ignore, from_tty)
  938.      char *ignore;
  939.      int from_tty;
  940. {
  941.   if (!selected_frame)
  942.     error ("No frame selected.");
  943.   print_frame_label_vars (selected_frame, 0, gdb_stdout);
  944. }
  945.  
  946. static void
  947. print_frame_arg_vars (frame, stream)
  948.      register FRAME frame;
  949.      register GDB_FILE *stream;
  950. {
  951.   struct symbol *func = get_frame_function (frame);
  952.   register struct block *b;
  953.   int nsyms;
  954.   register int i;
  955.   register struct symbol *sym, *sym2;
  956.   register int values_printed = 0;
  957.  
  958.   if (func == 0)
  959.     {
  960.       fprintf_filtered (stream, "No symbol table info available.\n");
  961.       return;
  962.     }
  963.  
  964.   b = SYMBOL_BLOCK_VALUE (func);
  965.   nsyms = BLOCK_NSYMS (b);
  966.  
  967.   for (i = 0; i < nsyms; i++)
  968.     {
  969.       sym = BLOCK_SYM (b, i);
  970.       switch (SYMBOL_CLASS (sym))
  971.     {
  972.     case LOC_ARG:
  973.     case LOC_LOCAL_ARG:
  974.     case LOC_REF_ARG:
  975.     case LOC_REGPARM:
  976.     case LOC_REGPARM_ADDR:
  977.     case LOC_BASEREG_ARG:
  978.       values_printed = 1;
  979.       fputs_filtered (SYMBOL_SOURCE_NAME (sym), stream);
  980.       fputs_filtered (" = ", stream);
  981.  
  982.       /* We have to look up the symbol because arguments can have
  983.          two entries (one a parameter, one a local) and the one we
  984.          want is the local, which lookup_symbol will find for us.
  985.          This includes gcc1 (not gcc2) on the sparc when passing a
  986.          small structure and gcc2 when the argument type is float
  987.          and it is passed as a double and converted to float by
  988.          the prologue (in the latter case the type of the LOC_ARG
  989.          symbol is double and the type of the LOC_LOCAL symbol is
  990.          float).  There are also LOC_ARG/LOC_REGISTER pairs which
  991.          are not combined in symbol-reading.  */
  992.  
  993.       sym2 = lookup_symbol (SYMBOL_NAME (sym),
  994.             b, VAR_NAMESPACE, (int *)NULL, (struct symtab **)NULL);
  995.       print_variable_value (sym2, frame, stream);
  996.       fprintf_filtered (stream, "\n");
  997.       break;
  998.  
  999.     default:
  1000.       /* Don't worry about things which aren't arguments.  */
  1001.       break;
  1002.     }
  1003.     }
  1004.  
  1005.   if (!values_printed)
  1006.     {
  1007.       fprintf_filtered (stream, "No arguments.\n");
  1008.     }
  1009. }
  1010.  
  1011. static void
  1012. args_info (ignore, from_tty)
  1013.      char *ignore;
  1014.      int from_tty;
  1015. {
  1016.   if (!selected_frame)
  1017.     error ("No frame selected.");
  1018.   print_frame_arg_vars (selected_frame, gdb_stdout);
  1019. }
  1020.  
  1021. /* Select frame FRAME, and note that its stack level is LEVEL.
  1022.    LEVEL may be -1 if an actual level number is not known.  */
  1023.  
  1024. void
  1025. select_frame (frame, level)
  1026.      FRAME frame;
  1027.      int level;
  1028. {
  1029.   register struct symtab *s;
  1030.  
  1031.   selected_frame = frame;
  1032.   selected_frame_level = level;
  1033.  
  1034.   /* Ensure that symbols for this frame are read in.  Also, determine the
  1035.      source language of this frame, and switch to it if desired.  */
  1036.   if (frame)
  1037.   {
  1038.     s = find_pc_symtab (get_frame_info (frame)->pc);
  1039.     if (s 
  1040.     && s->language != current_language->la_language
  1041.     && s->language != language_unknown
  1042.     && language_mode == language_mode_auto) {
  1043.       set_language(s->language);
  1044.     }
  1045.   }
  1046. }
  1047.  
  1048. /* Store the selected frame and its level into *FRAMEP and *LEVELP.
  1049.    If there is no selected frame, *FRAMEP is set to NULL.  */
  1050.  
  1051. void
  1052. record_selected_frame (frameaddrp, levelp)
  1053.      FRAME_ADDR *frameaddrp;
  1054.      int *levelp;
  1055. {
  1056.   *frameaddrp = selected_frame ? FRAME_FP (selected_frame) : 0;
  1057.   *levelp = selected_frame_level;
  1058. }
  1059.  
  1060. /* Return the symbol-block in which the selected frame is executing.
  1061.    Can return zero under various legitimate circumstances.  */
  1062.  
  1063. struct block *
  1064. get_selected_block ()
  1065. {
  1066.   if (!target_has_stack)
  1067.     return 0;
  1068.  
  1069.   if (!selected_frame)
  1070.     return get_current_block ();
  1071.   return get_frame_block (selected_frame);
  1072. }
  1073.  
  1074. /* Find a frame a certain number of levels away from FRAME.
  1075.    LEVEL_OFFSET_PTR points to an int containing the number of levels.
  1076.    Positive means go to earlier frames (up); negative, the reverse.
  1077.    The int that contains the number of levels is counted toward
  1078.    zero as the frames for those levels are found.
  1079.    If the top or bottom frame is reached, that frame is returned,
  1080.    but the final value of *LEVEL_OFFSET_PTR is nonzero and indicates
  1081.    how much farther the original request asked to go.  */
  1082.  
  1083. FRAME
  1084. find_relative_frame (frame, level_offset_ptr)
  1085.      register FRAME frame;
  1086.      register int* level_offset_ptr;
  1087. {
  1088.   register FRAME prev;
  1089.   register FRAME frame1;
  1090.  
  1091.   /* Going up is simple: just do get_prev_frame enough times
  1092.      or until initial frame is reached.  */
  1093.   while (*level_offset_ptr > 0)
  1094.     {
  1095.       prev = get_prev_frame (frame);
  1096.       if (prev == 0)
  1097.     break;
  1098.       (*level_offset_ptr)--;
  1099.       frame = prev;
  1100.     }
  1101.   /* Going down is just as simple.  */
  1102.   if (*level_offset_ptr < 0)
  1103.     {
  1104.       while (*level_offset_ptr < 0) {
  1105.     frame1 = get_next_frame (frame);
  1106.     if (!frame1)
  1107.       break;
  1108.     frame = frame1;
  1109.     (*level_offset_ptr)++;
  1110.       }
  1111.     }
  1112.   return frame;
  1113. }
  1114.  
  1115. /* The "select_frame" command.  With no arg, NOP.
  1116.    With arg LEVEL_EXP, select the frame at level LEVEL if it is a
  1117.    valid level.  Otherwise, treat level_exp as an address expression
  1118.    and select it.  See parse_frame_specification for more info on proper
  1119.    frame expressions. */
  1120.  
  1121. /* ARGSUSED */
  1122. static void
  1123. select_frame_command (level_exp, from_tty)
  1124.      char *level_exp;
  1125.      int from_tty;
  1126. {
  1127.   register FRAME frame, frame1;
  1128.   unsigned int level = 0;
  1129.  
  1130.   if (!target_has_stack)
  1131.     error ("No stack.");
  1132.  
  1133.   frame = parse_frame_specification (level_exp);
  1134.  
  1135.   /* Try to figure out what level this frame is.  But if there is
  1136.      no current stack, don't error out -- let the user set one.  */
  1137.   frame1 = 0;
  1138.   if (get_current_frame()) {
  1139.     for (frame1 = get_prev_frame (0);
  1140.      frame1 && frame1 != frame;
  1141.      frame1 = get_prev_frame (frame1))
  1142.       level++;
  1143.   }
  1144.  
  1145.   if (!frame1)
  1146.     level = 0;
  1147.  
  1148.   select_frame (frame, level);
  1149. }
  1150.  
  1151. /* The "frame" command.  With no arg, print selected frame briefly.
  1152.    With arg, behaves like select_frame and then prints the selected
  1153.    frame.  */
  1154.  
  1155. static void
  1156. frame_command (level_exp, from_tty)
  1157.      char *level_exp;
  1158.      int from_tty;
  1159. {
  1160.   select_frame_command (level_exp, from_tty);
  1161.   print_stack_frame (selected_frame, selected_frame_level, 1);
  1162. }
  1163.  
  1164. /* Select the frame up one or COUNT stack levels
  1165.    from the previously selected frame, and print it briefly.  */
  1166.  
  1167. /* ARGSUSED */
  1168. static void
  1169. up_silently_command (count_exp, from_tty)
  1170.      char *count_exp;
  1171.      int from_tty;
  1172. {
  1173.   register FRAME frame;
  1174.   int count = 1, count1;
  1175.   if (count_exp)
  1176.     count = parse_and_eval_address (count_exp);
  1177.   count1 = count;
  1178.   
  1179.   if (target_has_stack == 0 || selected_frame == 0)
  1180.     error ("No stack.");
  1181.  
  1182.   frame = find_relative_frame (selected_frame, &count1);
  1183.   if (count1 != 0 && count_exp == 0)
  1184.     error ("Initial frame selected; you cannot go up.");
  1185.   select_frame (frame, selected_frame_level + count - count1);
  1186. }
  1187.  
  1188. static void
  1189. up_command (count_exp, from_tty)
  1190.      char *count_exp;
  1191.      int from_tty;
  1192. {
  1193.   up_silently_command (count_exp, from_tty);
  1194.   print_stack_frame (selected_frame, selected_frame_level, 1);
  1195. }
  1196.  
  1197. /* Select the frame down one or COUNT stack levels
  1198.    from the previously selected frame, and print it briefly.  */
  1199.  
  1200. /* ARGSUSED */
  1201. static void
  1202. down_silently_command (count_exp, from_tty)
  1203.      char *count_exp;
  1204.      int from_tty;
  1205. {
  1206.   register FRAME frame;
  1207.   int count = -1, count1;
  1208.   if (count_exp)
  1209.     count = - parse_and_eval_address (count_exp);
  1210.   count1 = count;
  1211.   
  1212.   if (target_has_stack == 0 || selected_frame == 0)
  1213.     error ("No stack.");
  1214.  
  1215.   frame = find_relative_frame (selected_frame, &count1);
  1216.   if (count1 != 0 && count_exp == 0)
  1217.     {
  1218.  
  1219.       /* We only do this if count_exp is not specified.  That way "down"
  1220.      means to really go down (and let me know if that is
  1221.      impossible), but "down 9999" can be used to mean go all the way
  1222.      down without getting an error.  */
  1223.  
  1224.       error ("Bottom (i.e., innermost) frame selected; you cannot go down.");
  1225.     }
  1226.  
  1227.   select_frame (frame, selected_frame_level + count - count1);
  1228. }
  1229.  
  1230.  
  1231. static void
  1232. down_command (count_exp, from_tty)
  1233.      char *count_exp;
  1234.      int from_tty;
  1235. {
  1236.   down_silently_command (count_exp, from_tty);
  1237.   print_stack_frame (selected_frame, selected_frame_level, 1);
  1238. }
  1239.  
  1240. static void
  1241. return_command (retval_exp, from_tty)
  1242.      char *retval_exp;
  1243.      int from_tty;
  1244. {
  1245.   struct symbol *thisfun;
  1246.   FRAME_ADDR selected_frame_addr;
  1247.   CORE_ADDR selected_frame_pc;
  1248.   FRAME frame;
  1249.   value return_value = NULL;
  1250.  
  1251.   if (selected_frame == NULL)
  1252.     error ("No selected frame.");
  1253.   thisfun = get_frame_function (selected_frame);
  1254.   selected_frame_addr = FRAME_FP (selected_frame);
  1255.   selected_frame_pc = (get_frame_info (selected_frame))->pc;
  1256.  
  1257.   /* Compute the return value (if any -- possibly getting errors here).  */
  1258.  
  1259.   if (retval_exp)
  1260.     {
  1261.       return_value = parse_and_eval (retval_exp);
  1262.  
  1263.       /* Make sure we have fully evaluated it, since
  1264.      it might live in the stack frame we're about to pop.  */
  1265.       if (VALUE_LAZY (return_value))
  1266.     value_fetch_lazy (return_value);
  1267.     }
  1268.  
  1269.   /* If interactive, require confirmation.  */
  1270.  
  1271.   if (from_tty)
  1272.     {
  1273.       if (thisfun != 0)
  1274.     {
  1275.       if (!query ("Make %s return now? ", SYMBOL_SOURCE_NAME (thisfun)))
  1276.         {
  1277.           error ("Not confirmed.");
  1278.           /* NOTREACHED */
  1279.         }
  1280.     }
  1281.       else
  1282.     if (!query ("Make selected stack frame return now? "))
  1283.       error ("Not confirmed.");
  1284.     }
  1285.  
  1286.   /* Do the real work.  Pop until the specified frame is current.  We
  1287.      use this method because the selected_frame is not valid after
  1288.      a POP_FRAME.  The pc comparison makes this work even if the
  1289.      selected frame shares its fp with another frame.  */
  1290.  
  1291.   while ( selected_frame_addr != FRAME_FP (frame = get_current_frame())
  1292.        || selected_frame_pc   != (get_frame_info (frame))->pc  )
  1293.     POP_FRAME;
  1294.  
  1295.   /* Then pop that frame.  */
  1296.  
  1297.   POP_FRAME;
  1298.  
  1299.   /* Compute the return value (if any) and store in the place
  1300.      for return values.  */
  1301.  
  1302.   if (retval_exp)
  1303.     set_return_value (return_value);
  1304.  
  1305.   /* If interactive, print the frame that is now current.  */
  1306.  
  1307.   if (from_tty)
  1308.     frame_command ("0", 1);
  1309. }
  1310.  
  1311. /* Gets the language of the current frame. */
  1312. enum language
  1313. get_frame_language()
  1314. {
  1315.    register struct symtab *s;
  1316.    FRAME fr;
  1317.    enum language flang;        /* The language of the current frame */
  1318.    
  1319.    fr = get_frame_info(selected_frame);
  1320.    if(fr)
  1321.    {
  1322.       s = find_pc_symtab(fr->pc);
  1323.       if(s)
  1324.      flang = s->language;
  1325.       else
  1326.      flang = language_unknown;
  1327.    }
  1328.    else
  1329.       flang = language_unknown;
  1330.  
  1331.    return flang;
  1332. }
  1333.  
  1334. void
  1335. _initialize_stack ()
  1336. {
  1337. #if 0  
  1338.   backtrace_limit = 30;
  1339. #endif
  1340.  
  1341.   add_com ("return", class_stack, return_command,
  1342.        "Make selected stack frame return to its caller.\n\
  1343. Control remains in the debugger, but when you continue\n\
  1344. execution will resume in the frame above the one now selected.\n\
  1345. If an argument is given, it is an expression for the value to return.");
  1346.  
  1347.   add_com ("up", class_stack, up_command,
  1348.        "Select and print stack frame that called this one.\n\
  1349. An argument says how many frames up to go.");
  1350.   add_com ("up-silently", class_support, up_silently_command,
  1351.        "Same as the `up' command, but does not print anything.\n\
  1352. This is useful in command scripts.");
  1353.  
  1354.   add_com ("down", class_stack, down_command,
  1355.        "Select and print stack frame called by this one.\n\
  1356. An argument says how many frames down to go.");
  1357.   add_com_alias ("do", "down", class_stack, 1);
  1358.   add_com_alias ("dow", "down", class_stack, 1);
  1359.   add_com ("down-silently", class_support, down_silently_command,
  1360.        "Same as the `down' command, but does not print anything.\n\
  1361. This is useful in command scripts.");
  1362.  
  1363.   add_com ("frame", class_stack, frame_command,
  1364.        "Select and print a stack frame.\n\
  1365. With no argument, print the selected stack frame.  (See also \"info frame\").\n\
  1366. An argument specifies the frame to select.\n\
  1367. It can be a stack frame number or the address of the frame.\n\
  1368. With argument, nothing is printed if input is coming from\n\
  1369. a command file or a user-defined command.");
  1370.  
  1371.   add_com_alias ("f", "frame", class_stack, 1);
  1372.  
  1373.   add_com ("select-frame", class_stack, select_frame_command,
  1374.        "Select a stack frame without printing anything.\n\
  1375. An argument specifies the frame to select.\n\
  1376. It can be a stack frame number or the address of the frame.\n");
  1377.  
  1378.   add_com ("backtrace", class_stack, backtrace_command,
  1379.        "Print backtrace of all stack frames, or innermost COUNT frames.\n\
  1380. With a negative argument, print outermost -COUNT frames.");
  1381.   add_com_alias ("bt", "backtrace", class_stack, 0);
  1382.   add_com_alias ("where", "backtrace", class_alias, 0);
  1383.   add_info ("stack", backtrace_command,
  1384.         "Backtrace of the stack, or innermost COUNT frames.");
  1385.   add_info_alias ("s", "stack", 1);
  1386.   add_info ("frame", frame_info,
  1387.         "All about selected stack frame, or frame at ADDR.");
  1388.   add_info_alias ("f", "frame", 1);
  1389.   add_info ("locals", locals_info,
  1390.         "Local variables of current stack frame.");
  1391.   add_info ("args", args_info,
  1392.         "Argument variables of current stack frame.");
  1393.   add_info ("catch", catch_info,
  1394.         "Exceptions that can be caught in the current stack frame.");
  1395.  
  1396. #if 0
  1397.   add_cmd ("backtrace-limit", class_stack, set_backtrace_limit_command, 
  1398.        "Specify maximum number of frames for \"backtrace\" to print by default.",
  1399.        &setlist);
  1400.   add_info ("backtrace-limit", backtrace_limit_info,
  1401.         "The maximum number of frames for \"backtrace\" to print by default.");
  1402. #endif
  1403. }
  1404.